package com.xianyun.site.support.common;

import com.xianyun.site.support.SmsServiceImpl;
import com.xianyun.site.support.SmtpServiceImpl;
import com.xianyun.site.support.api.MessageService;
import com.xianyun.site.support.common.define.SupportTypeEnum;
import com.xianyun.site.support.common.utils.SpringBeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;
import static com.xianyun.site.support.common.define.SupportTypeEnum.SMS_MESSAGE;
import static com.xianyun.site.support.common.define.SupportTypeEnum.SMTP_MESSAGE;

/**
 * @author macos-zyj
 */
@Slf4j
public class MessageServiceFactory {

    private static final Map<SupportTypeEnum,Class> MESSAGE_SERVICE_MAP = new HashMap<>(16);

    static {
        MESSAGE_SERVICE_MAP.put(SMS_MESSAGE,  SmsServiceImpl.class);
        MESSAGE_SERVICE_MAP.put(SMTP_MESSAGE, SmtpServiceImpl.class);
    }

    private MessageServiceFactory(){

    }

    public static MessageService getMessageService(SupportTypeEnum typeEnum){
        MessageService resultService =(MessageService) SpringBeanUtil.getBean(MESSAGE_SERVICE_MAP.get(typeEnum));
        Assert.notNull(resultService,"MESSAGE_SUPPORT_TYPE_NOT_EXIST:消息类型不存在");
        return  resultService;
    }
}
